version 16

*This code must be run within the main do file. It will not run correctly on its own. 


clear

cap maptile_install using "http://files.michaelstepner.com/geo_county2000.zip"


use "$data/Replication_data.dta", replace
	
	local a_dry = " prec_dry below40_dry FND_Max40to45_dry FND_Max45to50_dry FND_Max50to55_dry FND_Max55to60_dry FND_Max60to65_dry FND_Max75to80_dry  FND_Max65to70_dry "
	
	local a_wet = " prec below40_wet FND_Max40to45_wet FND_Max45to50_wet FND_Max50to55_wet FND_Max55to60_wet FND_Max60to65_wet FND_Max75to80_wet  FND_Max65to70_wet "
	
	local b_dry = " c.Dividends#c.prec prec    c.Dividends#c.below40_dry c.Dividends#c.FND_Max40to45_dry c.Dividends#c.FND_Max45to50_dry c.Dividends#c.FND_Max50to55_dry c.Dividends#c.FND_Max55to60_dry c.Dividends#c.FND_Max60to65_dry c.Dividends#c.FND_Max75to80_dry  below40_dry FND_Max40to45_dry FND_Max45to50_dry FND_Max50to55_dry FND_Max55to60_dry FND_Max60to65_dry FND_Max75to80_dry FND_Max65to70_dry c.Dividends#c.FND_Max65to70_dry"	
	
	
	local b_wet = " c.Dividends#c.prec prec    c.Dividends#c.below40_wet c.Dividends#c.FND_Max40to45_wet c.Dividends#c.FND_Max45to50_wet c.Dividends#c.FND_Max50to55_wet c.Dividends#c.FND_Max55to60_wet c.Dividends#c.FND_Max60to65_wet c.Dividends#c.FND_Max75to80_wet  below40_wet FND_Max40to45_wet FND_Max45to50_wet FND_Max50to55_wet FND_Max55to60_wet FND_Max60to65_wet FND_Max75to80_wet  FND_Max65to70_wet c.Dividends#c.FND_Max65to70_wet"	
	

drop if year<1989
	drop if year>2011
	g recession=0
		foreach i in 1990 1991 2001 2002 2008 2009{
			replace recession=1 if year==`i'
		}
	bysort year: egen avg_div=mean(pc_Div)
		label var avg_div "Annual Avg. Dividends Per Capita ($000s)"
	egen avg_div1=mean(pc_Div) if year<2003
		label var avg_div1 "Pre-2003 Average"
	egen avg_div2=mean(pc_Div) if year>=2003
		label var avg_div2 "Post-2003 Average"
	
	egen Recessions = max(avg_div)
	twoway (bar Recessions year if recession==1, scheme(s1color) color(ltbluishgray) lcolor(ltbluishgray)) (line avg_div year, lcolor(black)) 	///
			(line avg_div1 year, lpattern(dash) lcolor(navy)) (line avg_div2 year, lpattern(dash) lcolor(navy) xline(2003)) 
			
	
				graph export "$output/images/Dividends_time_chart.png", as(png) replace 
		
	twoway (line pc_Div year if fips==25003, scheme(s1color) text(2.2 2004 "Pittsburgh, PA")) ///
		    (line mean_Div4 year if fips==25003 & year>1988 & year<1995,  lp(dash) lcolor(black)) ///
			(line mean_Div4 year if fips==25003 & year>1994 & year<2000, lp(dash) lcolor(black)) ///
			(line mean_Div4 year if fips==25003 & year>1999 & year<2005, lp(dash) lcolor(black)) ///
			(line mean_Div4 year if fips==25003 & year>2004, lp(dash) lcolor(black)) ///
			(lfit pc_Div year if fips==25003, lcolor(black)) ///
			(line mean_Div4 year if fips==26163 & year>1988 & year<1995, lp(dash) lcolor(black)) ///
			(line mean_Div4 year if fips==26163 & year>1994 & year<2000, lp(dash)lcolor(black)) ///
			(line mean_Div4 year if fips==26163 & year>1999 & year<2005, lp(dash) lcolor(black)) ///
			(line mean_Div4 year if fips==26163 & year>2004, lp(dash) lcolor(black)) ///
			(lfit pc_Div year if fips==26163, lcolor(black)) ///
			(line pc_Div year if fips==26163, text(.75 1998 "Detroit, MI") lpattern(dash_dot) legend(off)) 

				graph export "$output/images/PghvDet.png", as(png) replace 
		


preserve
	replace pc_Div=pc_Div*1000
	cap drop county
	rename fips county
	keep if year==1990
	sum pc_Div, d
		replace pc_Div=`r(p99)' if pc_Div>`r(p99)'
	maptile pc_Div , geo(county2000) conus  fcolor(Blues) cutvalues (200 400 600 800 1000 1200 1400) twopt( title("Dividends in 1990"))

		
		graph export "$output/images/Dividends Map (1990).png", as(png) replace 	
	
restore	

preserve	
	replace pc_Div=pc_Div*1000
	cap drop countyR
	rename fips county
	keep if year==2010
	sum pc_Div, d
		replace pc_Div=`r(p99)' if pc_Div>`r(p99)'
	maptile pc_Div , geo(county2000) conus fcolor(Blues) cutvalues (200 400 600 800 1000 1200 1400) twopt( title("Dividends in 2010"))
	
		
		graph export "$output/images/Dividends Map (2010).png", as(png) replace 	
			
restore	

outreg2 using "$output/sumstats.tex", sum(detail) replace keep(lny_nonag pc_Div days90plus_dry) eqkeep(N mean sd max min) tex(frag)

	
